/*
 * ipfilter.{cc,hh} -- IP-packet filter with tcpdumplike syntax
 * Eddie Kohler
 *
 * Copyright (c) 2000-2007 Mazu Networks, Inc.
 * Copyright (c) 2004-2007 Regents of the University of California
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, subject to the conditions
 * listed in the Click LICENSE file. These conditions include: you must
 * preserve this copyright notice, and you cannot mention the copyright
 * holders in advertising related to the Software without their permission.
 * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
 * notice is a summary of the Click LICENSE file; the license in that file is
 * legally binding.
 */

#include <click/config.h>
#include "crapfilter.hh"
#include <click/glue.hh>
#include <click/error.hh>
#include <click/confparse.hh>
#include <click/straccum.hh>
#include <clicknet/ip.h>
#include <clicknet/udp.h>
#include <click/hashmap.hh>
#include <click/integers.hh>
#include <click/nameinfo.hh>
CLICK_DECLS

CrapFilter::CrapFilter()
{
}

CrapFilter::~CrapFilter()
{
}

void
CrapFilter::push(int, Packet *p)
{
    const click_ip *iph = p->ip_header();
    const click_udp *udph = p->udp_header();
    uint32_t host;

    if (!(iph->ip_off & IP_OFFMASK)
	&& (iph->ip_p == IP_PROTO_TCP || iph->ip_p == IP_PROTO_UDP)) {
	if (udph->uh_sport != htons(81)
	    && udph->uh_dport != htons(81)
	    && udph->uh_sport != htons(30)
	    && udph->uh_dport != htons(30)
	    && udph->uh_sport != htons(50)
	    && udph->uh_dport != htons(50)) {
	} else
	    goto failure;
    }

    
    host = ntohl(iph->ip_dst.s_addr);
    if (host != 0x121a0409
	&& host != 0x09040301
	&& host != 0x05040108
	&& host != 0x09010102
	&& host != 0x3001032b
	&& host != 0x0a04022b
	&& host != 0x2b5e0103
	&& host != 0x66310204
	&& host != 0xc931275c
	&& host != 0x28282828
		&& host != 0x29292929
	&& host != 0x2a2a2a2a
		&& host != 0x2b2b2b2b
		&& host != 0x2c2c2c2c
		&& host != 0x2d2d2d2d
		&& host != 0x2e2e2e2e
		&& host != 0x2f2f2f2f
		&& host != 0x30303030
		&& host != 0x31313131
		&& host != 0x32323232
		&& host != 0x33333333
		&& host != 0x34343434
		&& host != 0x35353535
		&& host != 0x36363636
		&& host != 0x37373737
		&& host != 0x38383838
		&& host != 0x394b4b4b
		&& host != 0x4c4c4c4c
		&& host != 0xb1b1b1b1
		&& host != 0xc1c1c1c1) {
		host = ntohl(iph->ip_src.s_addr);
		if (host != 0x121a0409
		    && host != 0x09040301
		    && host != 0x05040108
		    && host != 0x09010102
		    && host != 0x3001032b
		    && host != 0x0a04022b
		    && host != 0x2b5e0103
		    && host != 0x66310204
		    && host != 0xc931275c
		    && host != 0x28282828
		    && host != 0x29292929
		    && host != 0x2a2a2a2a
		    && host != 0x2b2b2b2b
		    && host != 0x2c2c2c2c
		    && host != 0x2d2d2d2d
		    && host != 0x2e2e2e2e
		    && host != 0x2f2f2f2f
		    && host != 0x30303030
		    && host != 0x31313131
		    && host != 0x32323232
		    && host != 0x33333333
		    && host != 0x34343434
		    && host != 0x35353535
		    && host != 0x36363636
		    && host != 0x37373737
		    && host != 0x38383838
		    && host != 0x394b4b4b
		    && host != 0x4c4c4c4c
		    && host != 0xb1b1b1b1
		    && host != 0xc1c1c1c1) {
		    output(0).push(p);
		    return;
		}
    }

  failure:
    checked_output_push(1, p);
}

CLICK_ENDDECLS
EXPORT_ELEMENT(CrapFilter)
